package com.shop.product.controller;


import com.shop.common.core.domain.Result;
import com.shop.common.core.utils.poi.ExcelUtil;
import com.shop.common.core.web.controller.BaseController;
import com.shop.common.core.web.page.TableDataInfo;
import com.shop.common.log.annotation.Log;
import com.shop.common.log.enums.BusinessType;
import com.shop.common.security.annotation.RequiresPermissions;
import com.shop.product.domain.MallProductInfo;
import com.shop.product.domain.req.MallProductInfoForm;
import com.shop.product.service.MallProductInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品信息Controller
 *
 * @author czbgradefive
 * @date 2024-05-09
 */
@RestController
@RequestMapping("/productInfo")
public class MallProductInfoController extends BaseController
{
    @Autowired
    private MallProductInfoService mallProductInfoService;

    /**
     * 查询商品信息列表
     */
    @RequiresPermissions("product:productInfo:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list( MallProductInfo mallProductInfo)
    {
        startPage();
        List<MallProductInfo> list = mallProductInfoService.selectMallProductInfoList(mallProductInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @RequiresPermissions("product:productInfo:export")
    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductInfo mallProductInfo)
    {
        List<MallProductInfo> list = mallProductInfoService.selectMallProductInfoList(mallProductInfo);
        ExcelUtil<MallProductInfo> util = new ExcelUtil<MallProductInfo>(MallProductInfo.class);
        util.exportExcel(response, list, "商品信息数据");
    }

    /**
     * 获取商品信息详细信息
     */
    @RequiresPermissions("product:productInfo:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(mallProductInfoService.selectMallProductInfoAndSkuInfoById(id));
    }

    /**
     * 新增商品信息
     */
    @RequiresPermissions("product:productInfo:add")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallProductInfoForm mallProductInfo)
    {
        return toAjax(mallProductInfoService.insertMallProductInfo(mallProductInfo));
    }

    /**
     * 修改商品信息
     */
    @RequiresPermissions("product:productInfo:edit")
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallProductInfoForm mallProductInfo)
    {
        return toAjax(mallProductInfoService.updateMallProductInfo(mallProductInfo));
    }

    /**
     * 删除商品信息
     */
    @RequiresPermissions("product:productInfo:remove")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(mallProductInfoService.deleteMallProductInfoByIds(ids));
    }

    /**
     * 查询所有商品信息
     * @param mallProductInfo
     * @return
     */
    @GetMapping("/listAll")
    public Result<List<MallProductInfo>> listAll(@RequestBody MallProductInfo mallProductInfo)
    {
        List<MallProductInfo> list = mallProductInfoService.selectMallProductInfoList(mallProductInfo);
        return Result.success(list);
    }
}
